package com.jsh.erp.datasource.mappers;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.jsh.erp.datasource.entities.Sequence;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

@Mapper
public interface SequenceMapperEx extends BaseMapper<Sequence> {

    void updateBuildOnlyNumber(@Param("seq_name") String seq_name);

    /**
     * 获得一个全局唯一的数作为订单号的追加
     * */
    Long getBuildOnlyNumber(@Param("seq_name") String seq_name);

    default void existCreateDefault(String seqName){
        Sequence sequence = this.selectOne(new LambdaQueryWrapper<Sequence>().eq(Sequence::getSeqName, seqName).last("limit 1"));
        if(sequence==null){
            sequence = new Sequence();
            sequence.setCurrentVal(0l);
            sequence.setMaxValue(999999l);
            sequence.setIncrementVal(1);
            sequence.setMinValue(0l);
            sequence.setSeqName(seqName);
            this.insert(sequence);
        }
    }
}
